package stericson.XDA.metamorph;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;

public class DownloadPackages extends Activity {

	public ViewGroup mPackageList;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		// we set our view and we initialize everything
		setContentView(R.layout.listpackages);
		
		mPackageList = (ViewGroup) findViewById(R.id.packageListInfo);
		
	}

	// This reads a file and throws it into a variable.
	public void readwrite(String filename, boolean findpath) throws IOException {
		FileInputStream in = new FileInputStream(filename);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));

			
			int count = 0;
			String strLine;
			while ((strLine = br.readLine()) != null) {
				if (strLine.length() <= 1) {
					if (br.readLine().length() <= 1 && (strLine = br.readLine()) != null ) {
					count++;	
					}	
				}
			}
			
	}

	//======================================
	//Downloader
	//======================================
		
		// this is used to download zip.
		// However this can be used to download any file.
//		public void downloadfiles(boolean dowedosomethingelse, String dir, String saveto) {
//			URL n;
//			try {
//				if (dir.equals(null)) {
//				// url to download from + the file we want to download
//				n = new URL("http://www.relentlessaddictions.com/"
//						+ filetodownload);
//				}
//				else {
//					// url to download from + the dir + the file we want to download
//				n = new URL("http://www.relentlessaddictions.com/" + dir + "/"
//							+ filetodownload);
//				}
//				HttpURLConnection ulr = (HttpURLConnection) n.openConnection();
//				ulr.setRequestMethod("GET");
//				ulr.setDoOutput(true);
//				ulr.connect();
//				// where we want to save the file + the file name
//				FileOutputStream f = new FileOutputStream(new File(saveto + "/"
//						+ filetodownload));
//				InputStream urlin = ulr.getInputStream();

//				byte[] buffer = new byte[1024];
//				int len1 = 0;
//				while ((len1 = urlin.read(buffer)) != -1) {
//					f.write(buffer, 0, len1);
//				}
//				f.close();
//				urlin.close();
//			} catch (IOException e) {
//				// uhh we failed, let the user know.
//				mHandler1.post(mCompleteFailed1);
//				return;
//			}
//			//we only pass the handler is we are to do something. this may change.
//			if (dowedosomethingelse) {
//			// let the UI know the task is complete
//			mHandler1.post(mCompleteRunnable1);
//			}
//			patience.dismiss();
//		}
//		
//		mymsg = "We are downloading the latest list of packages...";
//		filetodownload = "currentpackages";
//	patience = ProgressDialog.show(
//			metamorph.this, "Please Wait",
//			mymsg, true);
//	Thread t = new Thread() {
//		public void run() {
//			// perform expensive tasks in a
//			// background thread
//			downloadfiles(false, "AndroidThemes", homer);
//		}
//	};
//	t.start();
//	}
//
//	// consume the selection event
//	return true;
//	
//}
	
	// and this goes with it
//	private final Runnable mCompleteFailed1 = new Runnable() {
//		public void run() {
//			patience.dismiss();
//			ourMessages(
//					"What the heck?! Do we have a connection? Something went wrong.",
//					true, true);
//		}
//	};
}
